﻿/*
' DotNetNuke® - http://www.dotnetnuke.com
' Copyright (c) 2002-2006
' by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
'
' Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
' documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
' the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
' to permit persons to whom the Software is furnished to do so, subject to the following conditions:
'
' The above copyright notice and this permission notice shall be included in all copies or substantial portions 
' of the Software.
'
' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
' TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
' THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
' CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
' DEALINGS IN THE SOFTWARE.
 */

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Xml;
using System.Web;
using DotNetNuke;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Services.Search;

namespace Triax.Modules.Department
{
    /// -----------------------------------------------------------------------------
    ///<summary>
    /// The Controller class for the ContractTemplateLog
    /// </summary>
    /// <remarks>
    /// </remarks>
    /// <history>
    /// </history>
    /// -----------------------------------------------------------------------------
    public class ContractTemplateLogController : ISearchable, IPortable
    {

        #region Constructors

        public ContractTemplateLogController()
        {
        }

        #endregion

        #region Public Methods

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// adds an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objContractTemplateLog">The ContractTemplateLog object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void AddContractTemplateLog(ContractTemplateLog objContractTemplateLog)
        {
            // if (objContractTemplateLog.ContractTemplateLogName.Trim() != "")
            {
                DataProvider.Instance().AddContractTemplateLog(objContractTemplateLog.ModuleId,

objContractTemplateLog.ContractTemplateID,
objContractTemplateLog.Type,
objContractTemplateLog.Publication,
objContractTemplateLog.UserCreate,
objContractTemplateLog.CreateDate,
objContractTemplateLog.FileDinhKem,
objContractTemplateLog.GhiChu,
objContractTemplateLog.TrangThai,
objContractTemplateLog.InsertDate,
objContractTemplateLog.UpdateDate,
objContractTemplateLog.CreateByUser,
objContractTemplateLog.UpdateByUser,
objContractTemplateLog.IsDelete,
objContractTemplateLog.tempInt1,
objContractTemplateLog.tempInt2,
objContractTemplateLog.tempInt3,
objContractTemplateLog.tempInt4,
objContractTemplateLog.tempStr1,
objContractTemplateLog.tempStr2,
objContractTemplateLog.tempStr3,
objContractTemplateLog.tempStr4,
objContractTemplateLog.tempDate1,
objContractTemplateLog.tempDate2

                    );
            }
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// deletes an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void DeleteContractTemplateLog(int ModuleId, int ContractTemplateLogId)
        {
            DataProvider.Instance().DeleteContractTemplateLog(ModuleId, ContractTemplateLogId);
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <param name="ItemId">The Id of the item</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public ContractTemplateLog GetContractTemplateLog(int ModuleId, int ContractTemplateLogId)
        {
            return CBO.FillObject<ContractTemplateLog>(DataProvider.Instance().GetContractTemplateLog(ModuleId, ContractTemplateLogId));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// gets an object from the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="moduleId">The Id of the module</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public List<ContractTemplateLog> GetContractTemplateLogs(int ModuleId)
        {
            return CBO.FillCollection<ContractTemplateLog>(DataProvider.Instance().GetContractTemplateLogs(ModuleId));
        }

        public List<ContractTemplateLog> GetContractTemplateLogsByCond(int ModuleId, string cond, string sql)
        {
            return CBO.FillCollection<ContractTemplateLog>(DataProvider.Instance().GetContractTemplateLogsByCond(ModuleId, cond, sql));
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// saves an object to the database
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="objContractTemplateLog">The ContractTemplateLog object</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void UpdateContractTemplateLog(ContractTemplateLog objContractTemplateLog)
        {
            // if (objContractTemplateLog.ContractTemplateLogName.Trim() != "")
            {
                DataProvider.Instance().UpdateContractTemplateLog(objContractTemplateLog.ModuleId,
                    objContractTemplateLog.ContractTemplateLogid,
objContractTemplateLog.ContractTemplateID,
objContractTemplateLog.Type,
objContractTemplateLog.Publication,
objContractTemplateLog.UserCreate,
objContractTemplateLog.CreateDate,
objContractTemplateLog.FileDinhKem,
objContractTemplateLog.GhiChu,
objContractTemplateLog.TrangThai,
objContractTemplateLog.InsertDate,
objContractTemplateLog.UpdateDate,
objContractTemplateLog.CreateByUser,
objContractTemplateLog.UpdateByUser,
objContractTemplateLog.IsDelete,
objContractTemplateLog.tempInt1,
objContractTemplateLog.tempInt2,
objContractTemplateLog.tempInt3,
objContractTemplateLog.tempInt4,
objContractTemplateLog.tempStr1,
objContractTemplateLog.tempStr2,
objContractTemplateLog.tempStr3,
objContractTemplateLog.tempStr4,
objContractTemplateLog.tempDate1,
objContractTemplateLog.tempDate2


                    );
            }
        }
        // End kết hợp xử lý
        #endregion

        #region Optional Interfaces

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// GetSearchItems implements the ISearchable Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModInfo">The ModuleInfo for the module to be Indexed</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public SearchItemInfoCollection GetSearchItems(ModuleInfo ModInfo)
        {
            SearchItemInfoCollection SearchItemCollection = new SearchItemInfoCollection();
            List<ContractTemplateLog> colContractTemplateLogs = GetContractTemplateLogs(ModInfo.ModuleID);

            foreach (ContractTemplateLog objContractTemplateLog in colContractTemplateLogs)
            {
                if (objContractTemplateLog != null)
                {
                    SearchItemInfo SearchItem = new SearchItemInfo();
                    SearchItemCollection.Add(SearchItem);
                }
            }

            return SearchItemCollection;
        }


        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ExportModule implements the IPortable ExportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be exported</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public string ExportModule(int ModuleID)
        {
            string strXML = "";
            List<ContractTemplateLog> colContractTemplateLogs = GetContractTemplateLogs(ModuleID);

            if (colContractTemplateLogs.Count != 0)
            {
                strXML += "<ContractTemplateLogs>";
                foreach (ContractTemplateLog objContractTemplateLog in colContractTemplateLogs)
                {
                    strXML += "<ContractTemplateLog>";
                    strXML += "<content>" + XmlUtils.XMLEncode(objContractTemplateLog.tempStr1) + "</content>";
                    strXML += "</ContractTemplateLog>";
                }
                strXML += "</ContractTemplateLogs>";
            }

            return strXML;
        }

        /// -----------------------------------------------------------------------------
        /// <summary>
        /// ImportModule implements the IPortable ImportModule Interface
        /// </summary>
        /// <remarks>
        /// </remarks>
        /// <param name="ModuleID">The Id of the module to be imported</param>
        /// <param name="Content">The content to be imported</param>
        /// <param name="Version">The version of the module to be imported</param>
        /// <param name="UserId">The Id of the user performing the import</param>
        /// <history>
        /// </history>
        /// -----------------------------------------------------------------------------
        public void ImportModule(int ModuleID, string Content, string Version, int UserId)
        {
            XmlNode xmlContractTemplateLogs = Globals.GetContent(Content, "ContractTemplateLogs");

            foreach (XmlNode xmlContractTemplateLog in xmlContractTemplateLogs.SelectNodes("ContractTemplateLog"))
            {
                ContractTemplateLog objContractTemplateLog = new ContractTemplateLog();

                objContractTemplateLog.ModuleId = ModuleID;
                //    objContractTemplateLog.ContractTemplateLogName = xmlContractTemplateLog.SelectSingleNode("content").InnerText;
                //      objContractTemplateLog.CreatedByUser = UserId;
                AddContractTemplateLog(objContractTemplateLog);
            }

        }

        #endregion

    }
}

